<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 16-3-8
 * Time: 下午2:23
 */

namespace Common\Model;
use Think\Model;

class MemberModel extends Model{
    //根据uid获取个人信息
    public function getUserByUid($uid){
    	$where['member_id'] = $uid;
    	return $this->getUser($where);
    }
    //根据uid获取个人信息
    public function getUpByPid($uid){
        $where['pid'] = $uid;
        return $this->getUser($where);
    }
    //根据uid获取个人详细信息
    public function getUserNoteByUid($uid){
    	$where['uid'] = $uid;
    	return $this->getUser($where);
    }
    //根据$username获取个人信息
    public function getUserByUsername($username){
    	$where['username'] = $username;
    	return $this->getUser($where);
    }
    //根据$email获取个人信息
    public function getUserByEmail($email){
    	$where['email'] = $email;
    	return $this->getUser($where);
    }
    //根据phone获取个人信息
    public function getUserByPhone($phone){
    	$where['phone'] = $phone;
    	return $this->getUser($where);
    }
    // like $username 获取uid 用于筛选
    public function getUserLikeUsername($username){
    	$where_username['username'] = array('like','%'.$username.'%');
    	return  M('Member')->where($where_username)->find()['id'];
    }
    //修改用户状态
    public function setUserStatus($uid,$status){
    	$where = $this->where;
    	$where['uid'] = $uid;
    	return M('Member')->where($where)->setField('status',$status);
    }
    //修改用户状态
    public function setUserLevel($uid,$level){
    	$where = $this->where;
    	$where['id'] = $uid;
    	return M('Member')->where($where)->setField('level',$level);
    }
    //新增用户
    public function addUser($data){
    	return M('Member')->add($data);
    }
    //修改用户
    public function saveUser($data,$uid){
    	return M('Member')->where(array('member_id'=>$uid))->save($data);
    }
    //根据username email phone 获取个人信息
    public function getUserByname($username){
    	$where['username'] = $username;
    	$where['email'] = $username;
    	$where['phone'] = $username;
    	$where['_logic'] = 'OR';
    	$where_and['status'] = array('neq',array(-2));
    	$where_and['_complex'] =$where;
    	$where_and['_logic'] ='AND';
    	return M('Member')->where($where_and)->find();
    }
    //根据条件获取用户
    public function getUser($where){
    	//$where['status'] = array('neq',-2);
    	return M('Member')->where($where)->find();
    }

}